package y_2025.m05.d23.test;


class Producer implements Runnable {
    private final SharedBuffer buffer;
    
    public Producer(SharedBuffer buffer) {
        this.buffer = buffer;
    }
    
    @Override
    public void run() {
        try {
            for (int i = 1; i <= 10; i++) {
                buffer.produce(i);
                Thread.sleep((int)(Math.random() * 1000)); // 随机生产间隔
            }
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }
}